package com.tekj.cxqcb.view.Module.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tekj.cxqcb.R;
import com.tekj.cxqcb.config.enums.EventBusMsgBean;
import com.tekj.cxqcb.operation.BusinessDao;
import com.tekj.cxqcb.operation.resultBean.SelectPublicTakeCarShopByUserIdBean;
import com.tekj.cxqcb.view.Module.activity.Address2Activity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import common.base.fragment.BaseFragment;
import common.base.operationHelper.Bean.BindingViewBean;

import static android.app.Activity.RESULT_OK;


public class ModifyAddress2Fragment extends BaseFragment {


    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_address)
    TextView tvAddress;

    BusinessDao businessDao;

    @Override
    public void init() {
        EventBus.getDefault().register(this);
        businessDao = new BusinessDao(activity, this);
    }

    @Override
    public int setLayout() {
        return R.layout.fragment_modify_address1;
    }

    @Override
    public void initLoadStart() {

    }

    @Override
    public void initLoadEnd() {

    }

    @Override
    public void initBindingView(Object mBean) {
        BindingViewBean bindingViewBean = (BindingViewBean) mBean;
        switch (bindingViewBean.getmEnumStatus()) {
            case 公用门店列表:
                SelectPublicTakeCarShopByUserIdBean byUserIdBean = (SelectPublicTakeCarShopByUserIdBean) bindingViewBean.getBean();
                if (byUserIdBean.getCode().equals("0000000")){

                }

                break;
        }
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void Event(EventBusMsgBean e) {
        switch (e.getmEnumStatus()) {
            case 提交门店地址:
                int type = (int) e.getObject();
                if (type == 1) {

                }
                break;
        }
    }


    @OnClick({R.id.tv_name, R.id.tv_address})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_name:
                startActivityForResult(new Intent(activity, Address2Activity.class), 104);
                break;

            case R.id.tv_address:
                businessDao.SelectPublicTakeCarShopByUserId(regionid, 1);
                break;
        }
    }

    String regionid, region, province, city;

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK)
            switch (requestCode) {
                case 104:
                    if (resultCode != RESULT_OK) {
                        return;
                    }
                    province = data.getStringExtra("province");
                    city = data.getStringExtra("city");
                    region = data.getStringExtra("district");
                    regionid = data.getStringExtra("region");
                    tvName.setText(province + " " + city + " " + region);
                    break;
            }
    }



}
